package message

import (
	"encoding/hex"
	"hy_808/protocol/hygprs"
	"strings"
)

/*
+0	80 00 3A 02 0E 2A 86
+7	01 00 00 00 34
+12	02 00 00 2C 8C
+17	03 21
+19	04 01 50 09 01
+24	06 62 1F 21 42
+29	07 04 27 E2 9B
+34	08 01 6F 26 23
+39	0A 00 00 速度
+42	0B 01 上下行
+44	0C 0B 站点号
+46	35 04 数据项类型
+48	0F 00 报警信息
+50	1A 01
+52	12 不定长数据ascii码方式 预留
+53	00 00 06 E8 81
+58
*/
type HighAlarm struct {
	hygprs.Fields
}

func GenHAlarm() HighAlarm {
	data, _ := hex.DecodeString(strings.ReplaceAll("80 00 45 02 B8 92 86 01 00 00 00 34 02 00 00 14 54 03 22 04 00 01 5F 22 06 62 21 AD BD 07 00 00 00 00 08 00 00 00 00 0A 00 00 0B 00 0C 01 35 FE 0F 01 1A 01 12 00 00 00 02 00 00 00 00 54 43 50 00 00 08 5E 81", " ", ""))
	return HighAlarm{hygprs.MakeFields(hygprs.MakePacket(data))}
}

//func (p HighAlarm) SetSpeed(v uint16) {
//	copy(p.Data[40:], hygprs.FromUint16(v))
//}
//
//func (p HighAlarm) SetRunDirection(v byte) {
//	p.Data[43] = v
//}
//
//func (p HighAlarm) SetStationNo(v byte) {
//	p.Data[45] = v
//}

type HAlarmType byte

const (
	HTSignIn HAlarmType = 0x4c
	HTGas    HAlarmType = 0x3e
)

func (p HighAlarm) SetDataType(v HAlarmType) {
	p.Data[47] = byte(v)
}

// 报警信息
func (p HighAlarm) SetData(v byte) {
	p.Data[49] = v
}

func (p HighAlarm) SetNote(v []byte) {
	p.Data = append(append(append([]byte{}, p.Data[:52]...), v...), p.Data[len(p.Data)-5:]...)
}

/*
80 00 3A 02 06 C5 86
01 00 00 00 34
02 00 00 2C 8C
03 21
04 00 03 15 DA
06 62 1F 19 DB
07 04 27 E2 AF
08 01 6F 26 12
0A 00 00
0B 01
0C 0B
35 4C
0F 01
1A 01
12
00 00 08 EF 81
*/
